package com.breadenglish.cms.api.app.common.utils;

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import java.io.File;

/**
 * 作者: guo yao
 * 日期: 2016年01月04日
 * 时间: 下午12:04
 */
public class VideoUtils {
    /**
     * 获取音频时长
     *
     * @param path
     * @return
     * @throws Throwable
     */
    public static String getVideoLength(String path) throws Throwable {
        File file = new File(path);
        Clip clip = AudioSystem.getClip();
        AudioInputStream ais = AudioSystem.getAudioInputStream(file);
        clip.open(ais);
//        System.out.println(clip.getMicrosecondLength() / 1000000D + " s");//获取音频文件时长
        return clip.getMicrosecondLength() / 1000000D + " s";
    }


    /**
     * 时间格式转换
     *
     * @param time
     * @return
     */
    public static String timeChangeover(Long time) {
        long hour = time / 3600;    //小时
        long minute = time % 3600 / 60;  //分钟
        long second = time % 60;        //秒
        return hour + ":" + minute + ":" + second;
    }
}
